<template>
  <div>
    <div class="content">
      <div>
        <div class="newshead">
          <div class="title-head" @click="xinwen" title="点击查看新闻">热点新闻</div>
        </div>
        <div class="newshead">
          <div class="title-head" @click="guangao" title="点击查看公告">公告</div>
        </div>
      </div>
      <div class="newsarea">
        <div class="location">
          <div class="selectname">
            {{selectName}}
          </div>
          <div class="local">
            <span>当前位置：</span>
            <span><a href="/">首页</a></span>
            <el-divider direction="vertical"></el-divider>
            <span><a href="#">新闻&公告</a></span>
          </div>
        </div>
        <!-- 新闻部分 -->
        <div class="area-content" v-show="selectName == '热点新闻'">
          <div class="item" v-for="(item,index) in newsList" :key="index" @click="newsdeatil(item)">
            <span class="span-area1">{{item.title}}</span>
            <span class="span-area2">{{item.updateTime}}</span>
          </div>
          <div class="pageBox">
            <el-pagination background layout="prev, pager, next" :page-size="20" :total=total @current-change="getpage">
            </el-pagination>
          </div>
        </div>
        <!-- 公告部分 -->
        <div class="area-content" v-show="selectName == '公告'">
          <div class="item" v-for="(item,index) in messageList" :key="index" @click="noticedeatil(item)">
            <span class="span-area1">{{item.title}}</span>
            <span class="span-area2">{{item.updateTime}}</span>
          </div>
          <div class="pageBox">
            <el-pagination background layout="prev, pager, next" :page-size="20" :total=total2
              @current-change="getpage">
            </el-pagination>
          </div>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'NewsTitle',
  data () {
    return {
      selectName: '热点新闻',
      pages: 1,
      newsList: [],
      messageList: [],
      total: 0,
      total2: 0
    }
  },
  methods: {
    newsdeatil (item) {
      this.$router.push({
        path: '/Deatil',
        query: {
          name: 'News',
          id: item.id
        }
      })
    },
    noticedeatil (item) {
      this.$router.push({
        path: '/Deatil',
        query: {
          name: 'Notice',
          id: item.id
        }
      })
    },
    xinwen () {
      this.selectName = '热点新闻'
    },
    guangao () {
      this.selectName = '公告'
    },
    getpage (e) {
      this.$axios({
        method: 'get',
        url: '/news/select?page=' + e + '&pageSize=20'
      }).then((res) => {
        if (res.status === 200) {
          this.newsList = res.data.data.rows
          this.total = res.data.data.records
        }
      })
      // 公告获取
      this.$axios({
        method: 'get',
        url: '/notice/select?page=' + e + '&pageSize=20'
      }).then((res) => {
        if (res.status === 200) {
          this.messageList = res.data.data.rows
          this.total2 = res.data.data.records
        }
      })
    },
    getData () {
      this.$axios({
        method: 'get',
        url: '/news/select?page=1&pageSize=20'
      }).then((res) => {
        if (res.status === 200) {
          this.newsList = res.data.data.rows
          this.total = res.data.data.records
        }
      })
      // 公告获取
      this.$axios({
        method: 'get',
        url: '/notice/select?page=1&pageSize=20'
      }).then((res) => {
        if (res.status === 200) {
          this.messageList = res.data.data.rows
          this.total2 = res.data.data.records
        }
      })
    }
  },
  mounted () {
    this.getData()
  }
}
</script>

<style scoped>
.content {
  background: white;
  height: 510px;
  padding: 20px 50px;
  display: flex;
}
.newshead {
  width: 300px;
  height: 60px;
  background: rgb(15, 66, 155);
  color: white;
  font-size: 25px;
  text-align: center;
  margin-bottom: 40px;
  overflow: hidden;
}
.newsarea {
  padding-left: 40px;
  width: 100%;
}
.location {
  height: 60px;
  display: flex;
  justify-content: space-between;
}
.area-content {
  height: 400px;
}
.selectname {
  color: #0f4a9b;
  font-size: 25px;
  height: 22px;
  margin: 20px 0;
}
.local {
  font-size: 18px;
  height: 22px;
  margin: 20px 0;
}
.title-head {
  line-height: 40px;
  margin: 10px 0;
  cursor: pointer;
}
a {
  text-decoration: none;
  color: black;
}
.item {
  font-size: 18px;
  height: 35px;
  margin: 5px 0;
  overflow: hidden;
  border-bottom: #eeeeee 1px solid;
}
.span-area1 {
  display: inline-block;
  margin: 5px 0;
  width: 600px;
  float: left;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.span-area2 {
  display: inline-block;
  margin: 5px 0;
  float: right;
  color: #cccccc;
}
.pageBox {
  position: relative;
}
.el-pagination {
  position: relative;
  left: 25%;
}
</style>
